package com.xbh.zzzTest.enumTest;

public enum Color {

    /*123*/
    RED(0, "红色"),
    BLUE(1, "蓝色"),
    YELLOW(2, "黄色"),
    GREEN(3, "绿色");

    private int code;
    private String desc;

    public int getCode() {
        return code;
    }

    public String getDesc() {
        return desc;
    }

    Color(int code, String desc) {
        this.code = code;
        this.desc = desc;
    }

    /**
     * @description: 通过颜色代码返回枚举对象
     * @param code 颜色的代码
     * @return: com.xbh.zzzTest.enumTest.Color 枚举对象
     * @author: ZBoHang
     * @time: 2021/7/22 16:02
     */
    public static Color getV(int code) {
        for (Color color : values()) {
            if (color.getCode() == code){
                return color;
            }
        }
        return null;
    }

}
